package org;

import org.example.entity.Product;
import org.example.service.ItemService;
import org.example.service.OrderService;
import org.example.service.ProductService;
import org.example.service.UserService;
import org.example.service.impl.ItemServiceImpl;
import org.example.service.impl.OrderServiceImpl;
import org.example.service.impl.ProductServiceImpl;
import org.example.service.impl.UserServiceImpl;

import java.util.Scanner;

public class Main {
    static UserService userService = new UserServiceImpl();
    static ProductService productService=new ProductServiceImpl();
    static OrderService orderService=new OrderServiceImpl();
    static ItemService itemService=new ItemServiceImpl();

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.println("==============电子商务================");
        System.out.println("请登录");
        System.out.println("请输入用户名");
        String userName = input.next();
        System.out.println("请输入密码");
        String password = input.next();
        boolean isLogin = userService.login(userName, password);
        if(isLogin) {
            while(true) {
                System.out.println("请选择；\n1、查询商品价格\n2、查看订单\n3、添加商品\n4、根据订单编号查询商品名称\n5、退出账号\n");
                // 调用其他service当中的方法完成对应的功能
                int num1=input.nextInt();
                if(num1==1){
                    System.out.println("请输入要查询的商品名字");
                    String name=input.next();
                    productService.getPriceByProName(name);
                }
                if(num1==2){
                    System.out.println("请输入要查看的订单Id");
                    int id=input.nextInt();
                    orderService.getOrdById(id);
                }
                if(num1==3){
                    System.out.println("请输入商品名称");
                    String name=input.next();
                    System.out.println("请输入商品数量");
                    int stock = input.nextInt();
                    System.out.println("请输入商品价格");
                    double price = input.nextDouble();
                    Product product = new Product(name,stock,price);
                    productService.addPro(product);
                }
                if(num1==4) {
                    System.out.println("请输入订单编号");
                    int orderId=input.nextInt();
                    itemService.getPronameByordId(orderId);
                }
                if(num1 == 5){
                    System.out.println("是否退出？y/n");
                    String exit = input.next();
                    if(exit.equals("yes")) {
                        return;
                    }
                }
            }
        }
    }
}
